
/*************
author:: libo
license:: MIT
*****************/
#ifndef MESH_FRAME_H
#define MESH_FRAME_H
#include "Cell_Traits.h"
/***********give some points p0 p1 ..pn then the
Antisymmetric tensor is

 (p1-p0)/\(p2-p0)/\...(pn-p0)*****

***/
#ifdef __cplusplus
extern "C"{
#endif
typedef struct Vertex{
    int id;
    double *point;
    int point_size;
   
    Node * cells;
    Node *faces;
    void *prop,*user_prop;
	VertexT traits;
}Vertex;

typedef struct HalfFace{
    int id;
    struct Vertex** vertices;
    int vertices_size;

    struct Cell* cell;
    struct Face* face;
    void *prop,*user_prop;
    HalfT traits;
}HalfFace;

typedef struct Face{
    int id;
    struct Vertex**vertices;
    int vertices_size;
    struct HalfFace* halffaces[2];
//int halffaces_size;

    void *prop,*user_prop;
    FaceT traits;
}Face;

typedef struct Cell{
    int id;

    struct Vertex**vertices;
    int vertices_size;
    Node* halffaces;
    void *prop,*user_prop;
    CellT traits;
}Cell;
//void Vertex_init_(Vertex*);
static inline void Vertex_init_(Vertex* pv)
{

    pv->cells=NULL;
    pv->faces=NULL;
    pv->id=-1;
    pv->point=NULL;
    pv->point_size=0;
    pv->prop=NULL;
    pv->user_prop=NULL;
    vertexT_init(&(pv->traits));
}
static inline void HalfFace_init_(HalfFace *hf)
{
    hf->vertices=NULL;
    hf->vertices_size=0;

    hf->cell=NULL;
    hf->face=NULL;
    hf->prop=NULL;
    hf->user_prop=NULL;
    hf->id=-1;
    halfT_init(&(hf->traits));
}


static inline void Face_init_(Face *f)
{
    f->prop=NULL;
    f->user_prop=NULL;
    f->vertices=NULL;
    f->id=-1;
    f->halffaces[0]=(template_hf*)malloc(sizeof(template_hf));
    f->halffaces[1]=(template_hf*)malloc(sizeof(template_hf));
    HalfFace_init_(f->halffaces[0]);
    HalfFace_init_(f->halffaces[1]);
    f->halffaces[0]->face=f;
    f->halffaces[1]->face=f;
     f->vertices_size=0;
    faceT_init(&(f->traits));
 
}
static inline void Cell_init_(Cell *pv)
{
    pv->vertices=NULL;
    pv->halffaces=NULL;
    pv->id=-1;
    pv->vertices_size=0;
    pv->prop=NULL;
    pv->user_prop=NULL;
    cellT_init(&(pv->traits));
}


void free_Vertex(Vertex*);
void free_Face(Face*);
void free_HalfFace(HalfFace*);
void free_Cell(Cell*);
void Halfface_remove_c(HalfFace*,Cell*);
void Face_remove_c(Face*,Cell*);
void Vertex_remove_f(Vertex*,Face*);
void Vertex_remove_c(Vertex*v,Cell*c);
void Cell_remove_f(Cell*,Face*);
#ifdef __cplusplus
}
#endif
#endif
